/**
 * StoreManager.java
 *
 * Copyright (C) 2009,  Tomislav Milkovic
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */
package extjsdyntran.translation.store;

import java.lang.reflect.Constructor;
import java.util.HashMap;

import org.slf4j.Logger;
import ws4is.engine.utils.LoggerFactory;

import extjsdyntran.translation.ITranslationService;

public class StoreManager {

	private static AStore sm ;
	final static Logger logger = LoggerFactory.get();
	
	public static boolean initStore(Class store, HashMap<String,String> params) {		
		 
		try {
			if (!AStore.class.isAssignableFrom(store)) throw new Exception("Class not of type " + AStore.class.getName());
			Class[] paramTypes = new Class[]{HashMap.class};
			Constructor co = store.getConstructor( paramTypes);
			sm =  (AStore) co.newInstance(params);
			return true;
		} catch (Exception e) {
			logger.error("Error initialization of store service {}", store.getName(), e);
			return false;
		}
					
	}
	
	public static boolean clearTranslation(ITranslationService service,String language){
		return sm.clearTranslation(service,language);
	}
	

	public static boolean deleteTranslation(String fromLanguage, String fromValue){
		return sm.deleteTranslation(fromLanguage, fromValue);
	}

	
	public static boolean saveTranslation(String toLanguage, String fromValue, String toValue){
		return sm.saveTranslation( toLanguage, fromValue, toValue);
	}
	
	public static boolean load(ITranslationService service,String [] lg) {
		return  sm.load(service,lg);		
	}

	public static boolean save(ITranslationService service,String language) {
	 	return sm.save(service,language);
	}


}
